﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DoAn.DTO;

namespace DoAn.BAN
{
    public partial class BanTrang2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            //    if (Session["SanPham"] != null)
            //    {
            //        SanDauGiaDTO san = new SanDauGiaDTO();
            //        san = (SanDauGiaDTO)Session["SanPham"];
            //        Response.Write("<script>alert('" + san.MaDanhMuc.ToString() + "')</script>");
            //    }
            //}
        }
        HttpFileCollection hfc;
        SanDauGiaDTO san = new SanDauGiaDTO();


        public bool KiemTraUpLoad()
        {                 
                 if (upcHinAnh.HasFile)
                 {
                     // Get the HttpFileCollection                
                     //for (int i = 1; i < hfc.Count; i++)
                     //{
                     //    HttpPostedFile hpf = hfc[i];
                     //    if (hpf.ContentLength > 0)
                     //    {
                     //        //hpf.SaveAs(Server.MapPath("Hinh") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
                     //        Response.Write("<script>alert('File: " + hpf.FileName + "  Size: " +
                     //         hpf.ContentLength + "  Type: " + hpf.ContentType + " Uploaded Successfully');</script>");
                     //    }
                     //}
                     return true;
                 }
                 else
                 {
                     return false;
                 }
        }

        protected void bntNext_Click(object sender, EventArgs e)
        {            
            if (!KiemTraUpLoad())
            {

                Response.Write("<script>alert('Phải chọn hình ảnh cho sản phẩm ')</script>");
            }
            else
            {
                san = (SanDauGiaDTO)HttpContext.Current.Session["SanPham"];
                san.TenSan = txtTenSanPham.Text;
                san.MoTa = txtMoTaNgan.Text;
                san.MoTaChiTiet = txtMoTaChiTiet.Html;
                hfc = Request.Files;
                for (int i = 1; i < hfc.Count; i++)
                {
                    HttpPostedFile hpf = hfc[i];
             
                    if (hpf.ContentLength > 0)
                    {
                        san.HinhAnh += hpf.FileName + ";";
                        
                    }
                }
                //Response.Write("<script>alert('" + san.MaDanhMuc.ToString() + "')</script>");

                Session["SanPham"] = san;
                Session["HinhAnh"] = hfc;
                Response.Redirect("~/BAN/BanTrang3.aspx");                
            }
        }

    }
}